package com.wy2cloud.authorize.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer;

/**
 * 资源服务认证配置
 * @author wuyy<16349023@qq.com>,nnsword
 * @date 2018年4月3日下午4:51:26
 *
 */
@Configuration
@EnableResourceServer
public class ResourceServerConfiguration extends ResourceServerConfigurerAdapter {
	
	private static final Logger logger=LoggerFactory.getLogger(ResourceServerConfiguration.class);
	
	@Value("${security.oauth2.client.client-id}")
	private String resoucreId;
	
    @Override
    public void configure(HttpSecurity http) throws Exception {
        // @formatter:off
        http.antMatcher("/client/userinfo").authorizeRequests().anyRequest().authenticated();
        // @formatter:on
    }
    
    @Override
    public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
    	resources.resourceId(resoucreId);
    	logger.info("Configuring ResourceServerSecurityConfigurer resoucreId:{}", resoucreId);
    }
}
